package byx.container.annotation.ConditionalTest.b;

import byx.container.annotation.annotation.Conditional;
import byx.container.annotation.annotation.Id;
import byx.container.annotation.annotation.Register;
import byx.container.core.Container;

import java.util.function.Predicate;

@Register
public class Config {
    @Register
    public A a() {
        return new A();
    }

    @Conditional(MyPredicate1.class)
    public B b(A a) {
        return new B(a);
    }

    @Conditional(MyPredicate2.class)
    @Id("ccccc")
    public C c(B b) {
        return new C(b);
    }

    @Conditional(MyPredicate3.class)
    public D d() {
        return new D();
    }

    @Register
    public E e() {
        return new E();
    }

    @Conditional(MyPredicate5.class)
    public F f(A a, E e) {
        return new F(a, e);
    }

    private static class MyPredicate1 implements Predicate<Container> {
        @Override
        public boolean test(Container container) {
            return container.exist(A.class);
        }
    }

    public static class MyPredicate2 implements Predicate<Container> {
        @Override
        public boolean test(Container container) {
            return container.exist(B.class);
        }
    }

    private static class MyPredicate3 implements Predicate<Container> {
        @Override
        public boolean test(Container container) {
            return container.exist(B.class) && container.exist(C.class);
        }
    }

    private static class MyPredicate5 implements Predicate<Container> {
        @Override
        public boolean test(Container container) {
            return container.exist(E.class);
        }
    }
}
